package com.bjx.generator.controller;

import com.bjx.common.core.domain.R;
import com.bjx.generator.domain.query.CreateCodeQuery;
import com.bjx.generator.service.ICreateCodeService;
import io.swagger.v3.oas.annotations.Operation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

/**
 * @desc: 代码生成接口
 * @author: liushuai
 * @date: 2022/9/22 15:26
 */
@RequestMapping("/create/code")
@RestController
public class CreateCodeController {
    @Resource
    private ICreateCodeService createCodeService;

    /**
     * 根据模板和表id下载生成的代码
     * @param createCodeQuery
     * @param response
     * @Author: liushuai
     * @Date: 2022/9/22
     */
    @PostMapping("/downloadCode")
    @Operation(summary = "根据模板和表id下载生成的代码")
    public void downloadCode(@RequestBody CreateCodeQuery createCodeQuery, HttpServletResponse response){
        createCodeService.downloadCode(createCodeQuery,response);
    }


    /**
     * 根据模板和表id创建代码
     * @param createCodeQuery
     * @Author: liushuai
     * @Date: 2022/9/22
     */
    @PostMapping("/createCode")
    @Operation(summary = "根据模板和表id创建代码")
    public R createCode(@RequestBody CreateCodeQuery createCodeQuery){
        createCodeService.createCode(createCodeQuery);
        return R.successMsg("生成代码成功");
    }




}
